//
//  LaunchViewController.m
//  DJILogin
//
//  Created by wenpd on 2021/3/31.
//

#import "LaunchViewController.h"
#import "LoginViewController.h"
#import <Masonry/Masonry.h>

#define LOGO         @"boot_logo.png"
#define THE_BUNDLE   @"DJILogin.bundle"

@interface LaunchViewController ()

@end

@implementation LaunchViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    [self initView];
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

- (void)viewDidAppear:(BOOL)animated {
    [super viewDidAppear:animated];
    
    [self customInitVC];
}

- (void)viewWillAppear:(BOOL)animated {
    [super viewWillAppear:animated];
    
    [self.navigationController setNavigationBarHidden:YES animated:NO];
    
    [self setNeedsStatusBarAppearanceUpdate];
}

- (BOOL)prefersStatusBarHidden {
    return YES;
}


- (void)initView{
    self.view.backgroundColor = [UIColor whiteColor];
    if(!self.imageView){
        UIImage *image = [UIImage imageNamed:LOGO];
        if(!image) {
            NSString *resourcePath = [[NSBundle mainBundle] resourcePath];
            NSString *bundlePath = [resourcePath stringByAppendingPathComponent:THE_BUNDLE];
            image = [UIImage imageNamed:LOGO inBundle:[NSBundle bundleWithPath:bundlePath] withConfiguration:nil];
        }
        self.imageView = [[UIImageView alloc]initWithImage:image];
    }
    [self.view addSubview:self.imageView];
    [self.imageView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(self.view.mas_top).offset(0);
        make.left.mas_equalTo(self.view.mas_left).offset(0);
        make.right.mas_equalTo(self.view.mas_right).offset(0);
        make.bottom.mas_equalTo(self.view.mas_bottom).offset(0);
    }];
}

- (void)customInitVC{
    if(_params) {
        BOOL needLogin = _params[@"needLogin"];
        UIViewController *targetContoller;
        if(!needLogin || [self checkLogin]){
            targetContoller = _params[@"ViewController"];  
        } else {
            //goto login page
            targetContoller = [[LoginViewController alloc]init];
        }
        if(targetContoller){
            [self.navigationController pushViewController:targetContoller animated:NO];
        }
    }
}

-(BOOL)checkLogin {
    return true;
}


@end
